package com.achao.basecommon.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @Description：jwt配置类
 * @date：2023/8/8 23:49
 */
@Configuration
public class JWTConfig implements WebMvcConfigurer {

    /**
     *  @Description：拦截器作为代理对象，能够解决redis无法在拦截器被spring容器实例化
     *      给bean添加命名是因为Bean冲突
     */
    @Bean(name = "jwtInter")
    public JwtInterceptor jwtInterceptor(){
        return new JwtInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())
                //上面表示需要有token的验证需要token
                .addPathPatterns("/achao/music/after/manager/**")
                //对路径user下面的路径不需要token验证  不需要拦截，就是对controller里面的路径进行拦截或者不拦截
                .excludePathPatterns("/achao/music/after/manager/loginManage")
        ;
    }

}
